﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.Objects;
using OpenWeb.Dal.Interfaces;

namespace OpenWeb.Dal.Infrastructure
{
    public class EFRepositoryContext : IRepositoryContext
    {
      private const string OBJECT_CONTEXT_KEY = "OpenWeb.Dal.EF.GoldCrmDbEntities";// contesto x entity f
        public IObjectSet<T> GetObjectSet<T>() 
            where T : class
        {
            return EFContextManager.GetObjectContext(OBJECT_CONTEXT_KEY).CreateObjectSet<T>();
          
        }


        /// <summary>
        /// Returns the active object context
        /// </summary>
        public ObjectContext ObjectContext
        {
            get
            {
                return EFContextManager.GetObjectContext(OBJECT_CONTEXT_KEY);
            }
        }

        public int SaveChanges()
        {
            return this.ObjectContext.SaveChanges();
        }

        public void Terminate()
        {
            EFContextManager.SetRepositoryContext(null, OBJECT_CONTEXT_KEY);
        }



        public System.Data.Entity.IDbSet<T> GetDbSet<T>() where T : class
        {
          throw new NotImplementedException();
        }

        public System.Data.Entity.DbContext DbContext
        {
          get { throw new NotImplementedException(); }
        }
    }
}
